Skip to content

Conversation

@dmcgowan
Copy link
Member

Prevents socket paths becoming too long when the resolved current working directory differs from the given bundle path, for example current working directory resolving to /private/var/... but the bundle directory reported as /var/.... The vm state directory does not need to be associated with a specific bundle and the working directory assigned to the shim is sufficient as the parent for the vm state directory.

Copilot AI review requested due to automatic review settings January 28, 2026 22:42
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR changes the vm state directory from being bundle-relative to current-working-directory-relative to prevent socket path length issues on macOS where path resolution can differ (e.g., /var vs /private/var).

Changes:

  • Modified vm state directory creation to use filepath.Abs("vm") instead of filepath.Join(r.Bundle, "vm")
  • Added error handling for the absolute path resolution
  • Added a comment explaining the rationale for the change

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

if err != nil {
return nil, errgrpc.ToGRPCf(err, "failed to resolve vm state directory")
}
if err := os.Mkdir(vmState, 0700); err != nil {
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The use of os.Mkdir will fail if the directory already exists. Since multiple containers can share the same VM instance (as evidenced by the containers map and the vmInstance guard), and the VM state directory is now shared across all containers in the same working directory, the second Create call will fail when trying to create the directory again. Consider using os.MkdirAll or checking for os.IsExist error to allow the directory to already exist.

Suggested change
if err := os.Mkdir(vmState, 0700); err != nil {
if err := os.MkdirAll(vmState, 0700); err != nil {

Copilot uses AI. Check for mistakes.
// vmState directory should be relative path to current working directory, not specific to a single bundle
vmState, err := filepath.Abs("vm")
if err != nil {
return nil, errgrpc.ToGRPCf(err, "failed to resolve vm state directory")
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message states "failed to resolve vm state directory" but filepath.Abs doesn't resolve in the sense of following symlinks or checking if the path exists - it just converts a relative path to an absolute one. Consider changing the message to "failed to get absolute path for vm state directory" to more accurately describe what could go wrong.

Suggested change
return nil, errgrpc.ToGRPCf(err, "failed to resolve vm state directory")
return nil, errgrpc.ToGRPCf(err, "failed to get absolute path for vm state directory")

Copilot uses AI. Check for mistakes.
b.AddExtraFile(nwcfg.Filename, nwJSON)

vmState := filepath.Join(r.Bundle, "vm")
// vmState directory should be relative path to current working directory, not specific to a single bundle
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment states that vmState should be a "relative path to current working directory" but the code uses filepath.Abs which returns an absolute path, not a relative one. The comment should be updated to accurately reflect that the vmState is now an absolute path based on the current working directory (e.g., "vmState directory should be in the current working directory, not specific to a single bundle").

Suggested change
// vmState directory should be relative path to current working directory, not specific to a single bundle
// vmState directory is an absolute path under the current working directory, not specific to a single bundle

Copilot uses AI. Check for mistakes.
Prevents socket paths becoming too long when the resolved current working
directory differs from the given bundle path, for example current
working directory resolving to `/private/var/...` but the bundle directory
reported as `/var/...`. The vm state directory does not need to be
associated with a specific bundle and the working directory assigned to
the shim is sufficient as the parent for the vm state directory.

Signed-off-by: Derek McGowan <derek@mcg.dev>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants